package com.mall.shopping.dto;

import com.mall.commons.result.AbstractRequest;
import com.mall.commons.tool.exception.ValidateException;
import com.mall.shopping.constants.ShoppingRetCode;
import lombok.Data;

/**
 * ciggar
 * create-date: 2019/7/24-16:29
 */
@Data
public class AllProductRequest extends AbstractRequest {

    private Integer page;
    private Integer size;
    private String sort;
    private Long cid;
    private Integer priceGt;
    private Integer priceLte;

    @Override
    public void requestCheck() {
        if (page <= 0) {
            setPage(1);
        }

        if (priceGt != null && priceLte == null) {
            if (priceGt < 0) {
                throw new ValidateException(ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getCode(), ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getMessage());
            }
        } else if (priceLte != null && priceGt == null) {
            if (priceLte < 0) {
                throw new ValidateException(ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getCode(), ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getMessage());
            }
        } else if (priceLte != null && priceGt != null) {
            if (priceGt < 0 || priceLte < 0) {
                throw new ValidateException(ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getCode(), ShoppingRetCode.PARAMETER_VALIDATION_FAILED.getMessage());
            }
        }

    }
}
